using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Speech.Synthesis;
using System.Text;

using Skypiee.Core;

using SKYPE4COMLib;

namespace SkypieeConsole
{
    class Program
    {
        static void Main(string[] args)
        {
            SkypieeCore core = new SkypieeCore();

            core.Start();

            core.ShowHardWiredGroups = false;
            core.LoadGroups();

            Console.WriteLine("Groups: {0}", core.Groups.Count);

            for (int i = 0; i < core.Groups.Count; i++)
            {
                IGroup group = core.Groups[i];

                Console.WriteLine("  {0} {1}", group.Id,
                    core.skype.Convert.GroupTypeToText(group.Type));



                core.LoadContacts(group);

                for (int j = 0; j < core.Contacts.Count; j++)
                {
                    SkypieeUser user = core.Contacts[j];
                 
                    Console.WriteLine("    {0} {1} {2}", user.Handle, user.DisplayName, user.FullName);
                }                
            }
            
            {
                IChat chat = core.skype.CreateChatWith("spiginko");

                chat.OpenWindow();

                /*
                for (int i = 0; i < 50; i++)
                {
                    System.Threading.Thread.Sleep(50);
                    chat.SendMessage(string.Format("Message: {0}", DateTime.Now.ToString()));
                }
                 */
            }
            
            //core.skype.

            ChatCollection chats = core.cSkype.ActiveChats;

            for (int i = 0; i < chats.Count; i++)
            {
                IChat chat = chats[i + 1];

                Console.WriteLine("  {0} {1} {2} {3} {4}",
                    chat.Name, chat.FriendlyName,
                    core.skype.Convert.ChatStatusToText(chat.Status),

                    chat.Members.Count, chat.Posters.Count);
            }

            while (true)
            {
                ChatMessageCollection msgs = core.cSkype.MissedMessages;

                for (int i = 0; i < msgs.Count; i++)
                {
                    IChatMessage msg = msgs[i + 1];

                    Console.WriteLine("{0} {1}", msg.ChatName, msg.Body);
                }

                if (Console.ReadLine().Contains("quit")) break;
            }

            //core.PlaceCall("spiginko");

            //System.Threading.Thread.Sleep(1000);

            core.LoadCalls();


            for (int i = 0; i < core.ActiveCalls.Count; i++)
            {
                ICall call = core.ActiveCalls[i + 1];

                Console.WriteLine("  {0} {1}", call.PartnerDisplayName, call.Status);

                /*
                {
                    SpeechSynthesizer synthesizer = new SpeechSynthesizer();
                    PromptBuilder promptBuilder = new PromptBuilder();

                    //promptBuilder.AppendBreak(new TimeSpan(0, 0, 2));
                    promptBuilder.StartStyle(new PromptStyle(PromptRate.Medium));

                    promptBuilder.AppendText("Finish a call to " + call.PartnerDisplayName);

                    promptBuilder.EndStyle();

                    synthesizer.Speak(promptBuilder);

                    core.FinishCall(call);
                }
                */
            }

        }
    }
}
